package com.hoaptt.pieces;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import com.hoaptt.helper.Coordinate;
import com.hoaptt.model.Board;
import java.util.ArrayList;

/**
 *
 * @author ThuHoa
 */
// Chariot : Xe
public class Chariot extends Piece {

    public Chariot(PLAYER player) {
        super(player);

        this.nameA = Character.toString((char)20453);
        this.nameB = Character.toString((char)63746);
        this.alias = NAMEPIECE.chariot;
    }

    @Override
    // this method is copy from class Cannon
 public ArrayList<Coordinate> generateMove(Board board, Coordinate loc) {
        ArrayList<Coordinate> ar = new ArrayList<Coordinate>();
        int X1[] = new int[]{1, 2, 3, 4, 5, 6, 7, 8};
        int Y1[] = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
        int X2[] = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
        int Y2[] = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        int X3[] = new int[]{-1, -2, -3, -4, -5, -6, -7, -8};
        int Y3[] = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
        int X4[] = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
        int Y4[] = new int[]{-1, -2, -3, -4, -5, -6, -7, -8, -9};

        for (int i = 0; i < X1.length; i++) {
            System.out.println("index: " + i);
            Coordinate coo = new Coordinate(loc.getRow() + X1[i], loc.getCol() + Y1[i]);

            // if don't exit a piece not default, add to array
            if (board.getAtLoc(coo) != null) {
                 System.out.println("location move: " + coo.getRow() + "\t" + coo.getCol());
                 System.out.println("alias at i: " + board.getAtLoc(coo).getAlias());
                if (board.getAtLoc(coo).getAlias() == null || board.getAtLoc(coo).getAlias() == Piece.NAMEPIECE.default1 ) {
                    ar.add(coo);
                } else {
                     if (board.getAtLoc(coo).getPlayer() != board.getAtLoc(loc).getPlayer())
                     {
                         ar.add(coo);
                         break;
                     }
                    break;
                }
            }

        }
        for (int i = 0; i < X2.length; i++) {
            Coordinate coo = new Coordinate(loc.getRow() + X2[i], loc.getCol() + Y2[i]);
            // if don't exit a piece not default, add to array
             if (board.getAtLoc(coo) != null) {
                 System.out.println("location move: " + coo.getRow() + "\t" + coo.getCol());
                 System.out.println("alias at i: " + board.getAtLoc(coo).getAlias());
               if (board.getAtLoc(coo).getAlias() == null || board.getAtLoc(coo).getAlias() == Piece.NAMEPIECE.default1 ) {
                    ar.add(coo);
                } else {
                     if (board.getAtLoc(coo).getPlayer() != board.getAtLoc(loc).getPlayer())
                     {  
                         ar.add(coo);
                         break;
                     }
                    break;
                }
            }
        }
        for (int i = 0; i < X3.length; i++) {
            Coordinate coo = new Coordinate(loc.getRow() + X3[i], loc.getCol() + Y3[i]);
            // if don't exit a piece not default, add to array
             if (board.getAtLoc(coo) != null) {
                 System.out.println("location move: " + coo.getRow() + "\t" + coo.getCol());
                 System.out.println("alias at i: " + board.getAtLoc(coo).getAlias());
                if (board.getAtLoc(coo).getAlias() == null || board.getAtLoc(coo).getAlias() == Piece.NAMEPIECE.default1 ) {
                    ar.add(coo);
                 } else {
                     if (board.getAtLoc(coo).getPlayer() != board.getAtLoc(loc).getPlayer())
                     {
                         ar.add(coo);
                         break;
                     }
                    break;
                }
            }
        }
        for (int i = 0; i < X4.length; i++) {
            Coordinate coo = new Coordinate(loc.getRow() + X4[i], loc.getCol() + Y4[i]);
            // if don't exit a piece not default, add to array
             if (board.getAtLoc(coo) != null) {
                 System.out.println("location move: " + coo.getRow() + "\t" + coo.getCol());
                 System.out.println("alias at i: " + board.getAtLoc(coo).getAlias());
               if (board.getAtLoc(coo).getAlias() == null || board.getAtLoc(coo).getAlias() == Piece.NAMEPIECE.default1 ) {
                    ar.add(coo);
                 } else {
                     if (board.getAtLoc(coo).getPlayer() != board.getAtLoc(loc).getPlayer())
                     {
                         ar.add(coo);
                         break;
                     }
                    break;
                }
            }
        }
        return ar;
    }

}
